/*
 * @(#)TestJConsoleLock.java 2017年11月12日下午1:20:50
 * Copyright 2013 sinovatech, Inc. All rights reserved.
 */
package com.lpf.testJVM;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 
 * <ul>
 * <li>
 * <b>修改历史：</b><br/>
 * <p>
 * [2017年11月12日下午1:20:50]liupeifeng<br/>
 * </p>
 * </li>
 * </ul>
 */

public class TestJConsoleLock {
	
	/**
	 * 线程死循环演示
	 */
	public static void createBusyThread() {
		Thread thread = new Thread(new Runnable() {
			
			@Override
			public void run() {
				while (true) {
					;
				}
			}
		}, "testBusyThread");
		
		thread.start();
	}
	
	/**
	 * 线程锁等待演示
	 */
	public static void createLockThread(final Object lock) {
		Thread thread = new Thread(new Runnable() {
			
			@Override
			public void run() {
				synchronized (lock) {
					try {
						lock.wait();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}, "testLockThread");
		
		thread.start();
	}
	
	

	/**
	 * @author liupeifeng
	 * @creationDate. 2017年11月12日 下午1:20:50 
	 * @param args
	 * @throws IOException 
	 */

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		br.readLine();
		createBusyThread();
		br.readLine();
		
		Object obj = new Object();
		createLockThread(obj);
	}

}
